<?
	use_db_wordpress();

	$query = mysql_query("SELECT * FROM `$wp_posts` ORDER BY `post_date`");

	if(!$query) {
		echo "<p>There are no posts.</p>";
	} else {
		while($row = mysql_fetch_array($query)) { /* Move the Posts: Contents and Meta */
			$id = "";
			$author = "";
			$staus = "";
			$type = "";
			$title = "";
			$content = "";
			$date = "";
			$comment_status = "";
			$edited_date = "";
			$page_parent = "";
			$page_order = "";
			$permalink_name = "";
			$menu_name = "";
			$lat = "";
			$lon = "";

			$id = $row['ID'];
			$author = $row['post_author'];
			$status = $row['post_status'];
			if((($status == "publish") || ($status == "draft") || ($status == "private")) && ($status != "static")) {
				$type = "blog";
			}
			if($status == "static") { 
				$type = "page";
				$status = "publish";
			}
			$title = addslashes($row['post_title']);
			$content = addslashes($row['post_content']);
			$post_date = strtotime($row['post_date_gmt']);
			$comment_status = $row['comment_status'];
			if($comment_status == "registered_only") { $comment_status = "closed"; }
			$edited_date = strtotime($row['post_modified_gmt']);
			$page_parent = $row['post_parent'];
			$page_order = $row['menu_order'];
			$permalink_name = $row['post_name'];
			$menu_name = ucwords(preg_replace('/-/', ' ', $row['post_name']));
			$lat = $row['lat'];
			$lon = $row['lon'];

			use_db_drizzo();
		
			$drizzo_insert = "INSERT INTO `$drizzo_posts` (`author`, `type`, `status`, `title`, `content`, `posted_date`, `comment_status`, `edited_date`, `import_id`, `page_parent`, `page_order`, `lat`, `lon`, `permalink_name`, `menu_name`) VALUES ('$author', '$type', '$status', '$title', '$content', '$post_date', '$comment_status', '$edited_date', '$id', '$page_parent', '$page_order', '$lat', '$lon', '$permalink_name', '$menu_name')";
		
			$insert_check = mysql_query($drizzo_insert);
			if(!$insert_check) {
				echo mysql_error() . "<br />";
			}
						
			use_db_wordpress();
			
		}
		
		use_db_drizzo();
		
		$page_count = mysql_num_rows(mysql_query("SELECT * FROM `$drizzo_posts` WHERE `type`='page'"));
		
		use_db_wordpress();

		$count = mysql_num_rows($query);
		$count = ($count - $page_count);
		echo "<p>" . $count . " Posts and " . $page_count . " Pages have been imported.</p>";
	}	
?>